<template>
	<view class="my-loading-main-box">
		<view class="loading-box">
			<image class="img" mode="widthFix" src="https://h5.sx2b2c.com/images/common/loading2.gif"></image>
			<view class="msg">{{showLoadingText}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "loading",
		props: ['countDown'],
		data() {
			return {
				currentCountDown: 0,
			};
		},
		computed: {
			showLoadingText() {
				if (this.countDown) {
					return '加载中' + this.currentCountDown + 's...'
				}
				return '加载中...'
			}
		},
		mounted() {
			if (this.countDown) {
				this.currentCountDown = this.countDown
			}
			this.initData()
		},
		methods: {
			initData() {
				if (this.currentCountDown) {
					setInterval(() => {
						if (this.currentCountDown > 0) {
							this.currentCountDown--
						}
					}, 1000)
				}
			}
		}
	}
</script>

<style lang="scss">
	.my-loading-main-box {
		display: flex;
		justify-content: center;
		align-items: center;
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100vh;
		z-index: 999999;

		.loading-box {
			width: 98%;
			padding: 24rpx 0;
			background-color: #fff;
			border-radius: 25rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;
			position: relative;

			.img {
				width: 100%;
				height: auto;
				display: block;
			}

			.msg {
				position: absolute;
				left: 50%;
				bottom: 40rpx;
				transform: translateX(-50%);
			}
		}
	}
</style>